//rematch 和原生redux的区别就是 它优化了这块的代码，可读性更强
import { init } from '@rematch/core'

interface State {
  topLabel:number
}
//开始使用rematch 大干一场吧
let store = {
  state: {
    // loaderOk: false,//是否加载成功
    topLabel:0,//头部标题的下标
    isLogin:false
  },
  //类似vuex 修改数据的那个函数
  reducers: {
    // setLocalCitysFun(state, payload){
    //   const newState= JSON.parse(JSON.stringify(state));
    //   newState.localCitys=payload;
    //   return newState;
    // }
    setTopLabelFun(state:State, index:number){
      const newState= JSON.parse(JSON.stringify(state));
      newState.topLabel=index;
      return newState;
    },
    setIsLoginFun(state:State){
      const newState= JSON.parse(JSON.stringify(state));
      newState.isLogin=true;
      return newState;
    },
  },
  //类似vuex 的action
  effects: {
    // navClick(index:number, state:any){
    //   (this as any).navClickFun(index)
    // },
    setTopLabelAct(index:number, state:any){
      (this as any).setTopLabelFun(index)
    },
    setIsLoginAct(state:any){
      (this as any).setIsLoginFun()
    },
  }
}
let returnStore = init(({
  models:{
    store
  }
} as any))
export default returnStore;